package user.internet;

import android.annotation.TargetApi;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.json.JSONException;
import org.json.JSONObject;
import org.xutils.common.Callback;
import org.xutils.http.RequestParams;
import org.xutils.x;

import base.Constant;

/**
 * Created by wangic on 2017/2/8.
 */
public class CurrentPeople_utlis {
    private static final String TAG = "CurrentPeople_utlis";

    public void CurrentPeople(final Handler handler) {
        RequestParams requestParams = new RequestParams(Constant.currentPeople_url);
        x.http().get(requestParams, new Callback.CommonCallback<JSONObject>() {
            @Override
            public void onSuccess(JSONObject result) {
                Log.e(TAG, "onSuccess: "+result.toString() );
                try {
                    Message message = new Message();
                    message.what = 2 ;
                    JSONObject data = (JSONObject) result.get("data");
                    message.obj = data.get("dayUsers");
                    handler.sendMessage(message);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                Message msg = new Message();
                msg.what = Constant.ERROR_MSG;
                handler.sendMessage(msg);

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }
}
